﻿using System;
using System.Collections.Generic;
using Hopscotch.Common.Contracts.AppService;

namespace Hopscotch.Server.AppServiceFake
{
	public class AuthenticationService : IAuthenticationService
	{
		private static bool isInitialized;

		private static Dictionary<string, string> userDictionary;

		public AuthenticationService()
		{
			Initialize();
		}

		private void Initialize()
		{
			if (isInitialized)
				return;

			userDictionary = new Dictionary<string, string>();
            userDictionary.Add("", "");
			userDictionary.Add("user", "1234");
			userDictionary.Add("admin", "1234");

			isInitialized = true;
		}


		public bool Login(string username, string passwordHash, string enviroment)
		{
			//Do a sanity test on the enviroment
			if (enviroment != "FKE")
			{
				throw new ApplicationException(string.Format("Invalid Target Enviroment '{0}'", enviroment));
			}

			if (userDictionary.ContainsKey(username))
			{
				return userDictionary[username].Equals(passwordHash, StringComparison.InvariantCulture);
			}

			return false;
		}
	}
}
